package com.Drools.CIPS.bean;

import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import lombok.ToString;

import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;
import java.util.Properties;

@Data
@AllArgsConstructor
@ToString
@NoArgsConstructor
public class DroolsReturn {
    private String language = "CN";
    private Boolean bo = true;
    private String errorSeverity;//异常等级
    private String errorCode;//异常码
    private String errorTest;//异常描述
    public DroolsReturn(Boolean bo){
        this.bo=bo;
    }
    public void setAll(String errorSeverity,String errorCode,String errorTest){
        this.bo = false;
        this.errorSeverity = errorSeverity;
        this.errorCode = errorCode;
        this.errorTest = errorTest;
    }
    public void setAll(String errorSeverity,String errorCode){
        this.bo = false;
        this.errorSeverity = errorSeverity;
        this.errorCode = errorCode;
        this.errorTest = this.getErrorTest(errorCode);
    }
    private String getErrorTest(String errorCode) {
        Properties properties = new Properties();
        //Hashtable的子类 常用来处理配置文件   key-value都是String
        try(FileReader fis = new FileReader("src/main/resources/errorCode/" +
                "errorText_" + language+ ".properties")) {
            properties.load(fis);//加载对应的文件
            return properties.getProperty(errorCode);
        } catch (FileNotFoundException e) {
            return "未找到对应异常描述";
        } catch (IOException e) {
            return "未找到对应异常描述";
        }
    }
}
